import { userApi } from '/api/user'
import { $utils } from '/utils'

/* eslint-disable @typescript-eslint/no-object-literal-type-assertion */

Page({
  data: {
    offset: 0,
    isLastPage: false,
    list: [] as DomoUser[],
  },
  onShow() {
    this.getfreinds()
  },
  onReachBottom() {
    this.getfreinds()
  },
  onPullDownRefresh() {
    this.setData({
      offset: 0,
      isLastPage: false,
      list: [] as DomoUser[],
    })
    this.getfreinds()
  },
  /** 获取好友 */
  async getfreinds() {
    if (this.data.isLastPage) return
    const list = await userApi.getFriends({ offset: this.data.offset, limit: 15 })
    const isLastPage = list.length < 15
    const offset = $utils.getLastField(list)
    this.setData({
      list: [...this.data.list, ...list],
      isLastPage,
      offset,
    })
  },
  /** 邀请 */
  invite(e: WechatMiniprogram.CustomEvent) {
    wx.showToast({
      title: '请通过右上角的胶囊进行分享邀请',
      icon: 'none',
    })
    // const {
    //   currentTarget: {
    //     dataset: { id },
    //   },
    // } = e
    this.onShareAppMessage()
  },

  onShareAppMessage() {
    const shareInfo: WechatMiniprogram.Page.ICustomShareContent = {
      path: $utils.getSharePath(),
    }
    return shareInfo
  },
})
